<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/WEB-INF/templates/template.xhtml"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	>
	<ui:define name="content">
		<ui:include src="/includes/menu.xhtml"></ui:include>
		
	<a4j:outputPanel id="contentpanel" layout="block">
    	<rich:panel style="float:left; width:800px; padding:5px;">
			<h1><h:outputText value="Content" /></h1>	
			<h:outputText value="#{contentBean.content.id}" />
			<h:outputText value="#{contentBean.content.content}"/>
			
			<h2><h:outputText value="Comments" /></h2>		
			<a4j:outputPanel id="panel" layout="block">
	          <a4j:repeat value="#{contentBean.comments}" var="comment" rows="20" id="repeat">
	              <rich:panel style="float:left; width:750px; padding:5px;">
	                  <f:facet name="header">
	                      <h:panelGroup>
	                       	<h:panelGrid columns="2">
	                       	   <h:outputText value="#{comment.date} : " />
	                           <h:outputText value="#{comment.webuser.nick} " />
	                  		</h:panelGrid>
	                  		<h:panelGrid columns="1">
	                       	   <h:outputText value="#{comment.title}" />
	                  		</h:panelGrid>
	                      </h:panelGroup>
	                  </f:facet>
	                  <h:panelGrid columns="1">
	                      <h:outputText value="#{comment.text}" />
	                  </h:panelGrid>
	                  <h:panelGrid columns="1" style="float:right;" rendered="#{contentBean.admin}">
	                      <h:form>
							<h:commandButton value="delete" action="#{contentBean.deleteComment(comment.id)}" />
						  </h:form>
	                  </h:panelGrid>
	              </rich:panel>
	          </a4j:repeat>
	       </a4j:outputPanel>
       </rich:panel>
       </a4j:outputPanel>
       
       <a4j:outputPanel id="fragmentpanel" layout="block" >
   			<rich:panel style="float:left; width:800px; padding:5px;" >
   			<h3><h:outputText value="Nový komentář" /></h3>
   				   <rich:panel rendered="#{loginBean.isLogged()}">
				   <h:form id="addComment" rendered="#{contentBean.admin}" >
							<h:panelGrid columns="2">
								<h:outputText value="Nadpis:" />
								<h:inputText value="#{contentBean.commentTitle}" />
								<h:outputText value="Text:" />
								<h:inputTextarea value="#{contentBean.commentText}" />
							</h:panelGrid>
							<h:commandButton value="Komentuj" action="#{contentBean.createComment(contentBean.content.id)}" />
				   </h:form>
				   </rich:panel>
				   <rich:panel rendered="#{!loginBean.isLogged()}">
				   		<h:outputText value="Pro možnost přidávat komentáře se prosím přihlašte." />
				   </rich:panel>
	   		</rich:panel>
	  </a4j:outputPanel>
	</ui:define>
</ui:composition>